use enigo::{Enigo, MouseButton, MouseControllable};
use std::env::args;

fn help() {
    println!("./cmd <time> <x> <y>");
}

fn parser_args() -> (i32, i32, i32) {
    let args: Vec<_> = args()
        .map(|x| x.parse())
        .filter(|x| x.is_ok())
        .map(|x| x.unwrap())
        .collect();
    if args.len() != 3 {
        help();
        std::process::exit(0);
    }
    (args[0], args[1], args[2])
}

fn main() {
    let mut enigo = Enigo::new();
    let (time, x, y) = parser_args();
    loop {
        std::thread::sleep(std::time::Duration::from_secs(time as u64));
        enigo.mouse_move_to(x * 2 / 3, y * 2 / 3);
        enigo.mouse_click(MouseButton::Left);
    }
}
